package com.harboursoftware.xstorage.unit.ac
;

import com.harboursoftware.xstorage.ac.CanonicalUserGrantee 
import com.harboursoftware.xstorage.model.XUser 
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

class CanonicalUserGranteeTest {
	def grantee
    def grantee2
	@Before
	void setUp() {
		grantee = new CanonicalUserGrantee()
        grantee2 = new CanonicalUserGrantee()
	}
	
	@After
	void tearDown() {
		grantee = null
        grantee2 = null;
	}
	
	@Test
	void testContains1() {
		def user = new XUser(id : '123456')
		assert !grantee.contains(user)
	}
	
	@Test
	void testContains2() {
		grantee.id = '123456'
		def user = new XUser(id : '123456')
		assert grantee.contains(user)
	}
	
	@Test
	void testContains3() {
		grantee.id = '123456'
		def user = null
		assert !grantee.contains(user)
	}
	
	@Test
	void testToXML() {
		grantee.id = 'a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9'
		grantee.displayName = 'chriscustomer'
		String expectedXML = '<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">' + 
		                     '<ID>a9a7b886d6fd24a52fe8ca5bef65f89a64e0193f23000e241bf9b1c61be666e9</ID>' +
		                     '<DisplayName>chriscustomer</DisplayName>' +
		                     '</Grantee>'
		assert grantee.toXML() == expectedXML
	}
    
    @Test
    void testEquals() {
        assert grantee.equals(grantee2)
    }
    
    @Test
    void testEquals2() {
        grantee.id = '111'
        grantee2.id = '111'
        assert grantee.equals(grantee2)
    }
}
